/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ufrgs.inf.delphos.extraction.model.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENamedElementImpl;

import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;

import ufrgs.inf.delphos.extraction.model.DAnnotation;
import ufrgs.inf.delphos.extraction.model.DCompilationUnit;
import ufrgs.inf.delphos.extraction.model.DRelation;
import ufrgs.inf.delphos.extraction.model.DelphosSystemModelPackage;
import ufrgs.inf.delphos.identification.knowledgebase.Tag;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>DCompilation Unit</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ufrgs.inf.delphos.extraction.model.impl.DCompilationUnitImpl#getAnnotationsList <em>Annotations</em>}</li>
 *   <li>{@link ufrgs.inf.delphos.extraction.model.impl.DCompilationUnitImpl#getRelationsList <em>Relations</em>}</li>
 *   <li>{@link ufrgs.inf.delphos.extraction.model.impl.DCompilationUnitImpl#getTagsList <em>Tags</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DCompilationUnitImpl extends ENamedElementImpl implements DCompilationUnit {
	/**
	 * The cached value of the '{@link #getAnnotationsList() <em>Annotations</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAnnotationsList()
	 * @generated
	 * @ordered
	 */
	protected EList<DAnnotation> annotations;

	/**
	 * The empty value for the '{@link #getAnnotations() <em>Annotations</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAnnotations()
	 * @generated
	 * @ordered
	 */
	protected static final DAnnotation[] ANNOTATIONS_EEMPTY_ARRAY = new DAnnotation [0];

	/**
	 * The cached value of the '{@link #getRelationsList() <em>Relations</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRelationsList()
	 * @generated
	 * @ordered
	 */
	protected EList<DRelation> relations;

	/**
	 * The empty value for the '{@link #getRelations() <em>Relations</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRelations()
	 * @generated
	 * @ordered
	 */
	protected static final DRelation[] RELATIONS_EEMPTY_ARRAY = new DRelation [0];

	/**
	 * The cached value of the '{@link #getTagsList() <em>Tags</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTagsList()
	 * @generated
	 * @ordered
	 */
	protected EList<Tag> tags;

	/**
	 * The empty value for the '{@link #getTags() <em>Tags</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTags()
	 * @generated
	 * @ordered
	 */
	protected static final Tag[] TAGS_EEMPTY_ARRAY = new Tag [0];

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DCompilationUnitImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DelphosSystemModelPackage.Literals.DCOMPILATION_UNIT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DAnnotation[] getAnnotations() {
		if (annotations == null || annotations.isEmpty()) return ANNOTATIONS_EEMPTY_ARRAY;
		BasicEList<DAnnotation> list = (BasicEList<DAnnotation>)annotations;
		list.shrink();
		return (DAnnotation[])list.data();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DAnnotation getAnnotations(int index) {
		return getAnnotationsList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getAnnotationsLength() {
		return annotations == null ? 0 : annotations.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAnnotations(DAnnotation[] newAnnotations) {
		((BasicEList<DAnnotation>)getAnnotationsList()).setData(newAnnotations.length, newAnnotations);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAnnotations(int index, DAnnotation element) {
		getAnnotationsList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DAnnotation> getAnnotationsList() {
		if (annotations == null) {
			annotations = new EObjectContainmentEList<DAnnotation>(DAnnotation.class, this, DelphosSystemModelPackage.DCOMPILATION_UNIT__ANNOTATIONS);
		}
		return annotations;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DRelation[] getRelations() {
		if (relations == null || relations.isEmpty()) return RELATIONS_EEMPTY_ARRAY;
		BasicEList<DRelation> list = (BasicEList<DRelation>)relations;
		list.shrink();
		return (DRelation[])list.data();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DRelation getRelations(int index) {
		return getRelationsList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getRelationsLength() {
		return relations == null ? 0 : relations.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRelations(DRelation[] newRelations) {
		((BasicEList<DRelation>)getRelationsList()).setData(newRelations.length, newRelations);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRelations(int index, DRelation element) {
		getRelationsList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DRelation> getRelationsList() {
		if (relations == null) {
			relations = new EObjectContainmentEList<DRelation>(DRelation.class, this, DelphosSystemModelPackage.DCOMPILATION_UNIT__RELATIONS);
		}
		return relations;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Tag[] getTags() {
		if (tags == null || tags.isEmpty()) return TAGS_EEMPTY_ARRAY;
		BasicEList<Tag> list = (BasicEList<Tag>)tags;
		list.shrink();
		return (Tag[])list.data();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Tag getTags(int index) {
		return getTagsList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getTagsLength() {
		return tags == null ? 0 : tags.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTags(Tag[] newTags) {
		((BasicEList<Tag>)getTagsList()).setData(newTags.length, newTags);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTags(int index, Tag element) {
		getTagsList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Tag> getTagsList() {
		if (tags == null) {
			tags = new EDataTypeUniqueEList<Tag>(Tag.class, this, DelphosSystemModelPackage.DCOMPILATION_UNIT__TAGS);
		}
		return tags;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__ANNOTATIONS:
				return ((InternalEList<?>)getAnnotationsList()).basicRemove(otherEnd, msgs);
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__RELATIONS:
				return ((InternalEList<?>)getRelationsList()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__ANNOTATIONS:
				return getAnnotationsList();
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__RELATIONS:
				return getRelationsList();
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__TAGS:
				return getTagsList();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__ANNOTATIONS:
				getAnnotationsList().clear();
				getAnnotationsList().addAll((Collection<? extends DAnnotation>)newValue);
				return;
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__RELATIONS:
				getRelationsList().clear();
				getRelationsList().addAll((Collection<? extends DRelation>)newValue);
				return;
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__TAGS:
				getTagsList().clear();
				getTagsList().addAll((Collection<? extends Tag>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__ANNOTATIONS:
				getAnnotationsList().clear();
				return;
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__RELATIONS:
				getRelationsList().clear();
				return;
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__TAGS:
				getTagsList().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__ANNOTATIONS:
				return annotations != null && !annotations.isEmpty();
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__RELATIONS:
				return relations != null && !relations.isEmpty();
			case DelphosSystemModelPackage.DCOMPILATION_UNIT__TAGS:
				return tags != null && !tags.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (tags: ");
		result.append(tags);
		result.append(')');
		return result.toString();
	}

} //DCompilationUnitImpl
